// 代理接口
const path = require('path')
const proxy = require('http-proxy-middleware') //引入代理中间件

const resolve = file => path.resolve(__dirname, file)
const config = require(resolve('../config/env.js'))

let proxyArr = config.proxyArr   
proxyArr = []

let api = 'http://127.0.0.1:5000'
/****** 设置代理Proxy ******/
module.exports = app => {

  // proxyArr.forEach(item => {
  //   console.log('proxy',app);
  //   app.use(
  //     item.proxy,
  //     proxy({
  //       target: item.target,
  //       changeOrigin: true,
  //       // pathRewrite: { [`^${item.proxy}`]: item.proxy }
  //       pathRewrite: { '^/my_api': '' }
  //     })
  //   )
  // })
  app.use(
    '/my_api',
    (req,res,next)=>{
      console.log('middle===========',req.url);
      next()
    },
    proxy({
      target: 'http://127.0.0.1:5000',
      changeOrigin: true,
      pathRewrite: { '^/my_api': ''}
    })
  )
}
